<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="UTF-8">
  <title>Redis 热搜榜</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" >
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" ></script>
</head>
<body>
  <div class="container">
    <div class="left_nav">
        <ui>
            <li data-type="hour"><a href="#">小时</a></li>
            <li data-type="day" class="active"><a href="#">24时</a></li>
            <li data-type="week"><a href="#">周榜</a></li>
            <li data-type="month"><a href="#">月榜</a></li>
        </ui>
    </div>
    <div class="row hot_main">
      <div class="col-md-7">
        <div class="hot-search-th">
          <span>排名</span>
          <span>热点</span>
          <span>热搜指数</span>
        </div>
        <ul class="list-group hot-search" >
<!--          <li class="list-group-item list-group-item-info" th:each="rankList:${rankList}" th:classappend="${rankListStat.index} < 3 ? 'highlight':'' ">-->
<!--            <span th:text="${rankListStat.index+1}" class="badges"></span>-->
<!--            <span th:text="${rankList.value}"></span>-->
<!--            <span th:text="${rankList.score}"></span>-->
<!--          </li>-->
        </ul>
      </div>
      <div class="col">
        <form th:action="@{/search}" method="post">
          <div class="input-group form-group">
            <input type="text" name="member" class="form-control" id="search" aria-label="...">
            <span class="input-group-addon">
              <input class="form-control" type="number" name="times" style="width: 100px" value="1"/>
            </span>
            <span class="input-group-btn">
              <button class="btn btn-primary" type="submit">搜索一下</button>
            </span>
          </div>
        </form>
      </div>
    </div>
  </div>

</body>
<script>
    $(window).load(function(){
        request()
    });

    $(".left_nav li").click(function () {
        $(this).addClass("active").siblings().removeClass("active");
        request($(this).data("type"))
    })

    function request(type) {
        if (type == undefined || type == "") {
            type = "day"
        }
        $.ajax({
            type: "POST",
            contentType: "application/json",
            url: "/rankList?type="+type,
            data: "",
            success: function (res) {
                var rankList = res.data
                var html = "";
                if (rankList.length == 0) {
                    html = "<li style=\"text-align:center;list-style: none\">未找到数据</li>"
                }
                if (res.status == 200) {
                    for (var i = 0;i < rankList.length; i++){
                        var course = rankList[i];
                        html += "<li class=\"list-group-item list-group-item-info " + ((i < 3)? 'highlight':'') + "\">\n" +
                                    "<span class=\"badges\">" + (i+1) + "</span>" +
                                    "<span>" + course.value + "</span>\n" +
                                    "<span>" + course.score + "</span>\n"

                    }
                }
                $(".hot-search").html(html);//写入ui中
            },
            error: function (e) {
                console.error(e.responseJSON.message)
            }
        })
    }
</script>
  <style>
    .container {
      margin-top: 20px;
    }
    .left_nav {
        width: 140px;
        float: left;
        border-top: 2px #237dad solid;
        background: #fff;
        margin-right: 10px;
        margin-top: 25px;
    }
    .left_nav li.active {
        background-color: #237dad;
    }
    .left_nav li:hover {
        background-color: #7ea1b4;
    }
    .left_nav li.active a{
        color: white;
    }
    .left_nav li a {
        text-decoration: none;
        text-align: center;
        font-size: 18px;
        line-height: 35px;
    }
    .left_nav li {
        list-style: none;
        height: 35px;
        margin: 1px 0;
        display: list-item;
        text-align: center;
        background-color: #e3fcfd;
        color: black;
        cursor: pointer;
    }
    .hot_main {
        width: calc(100% - 155px);
        float: left;
    }
    .hot-search-th {
      border-bottom: solid 1px silver;
      margin-bottom: 5px;
    }
    .hot-search span,.hot-search-th span {
      display: inline-block;
      height: 20px;
      line-height: 20px;
      font-size: 16px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .hot-search span:nth-child(1),.hot-search-th span:nth-child(1) {
      width: 50px;
    }
    .hot-search span:nth-child(2),.hot-search-th span:nth-child(2) {
      width: 460px;
    }
    .hot-search-th span:nth-child(2) {
      padding-left: 16px;;
    }

    .highlight span {
      color: red;
      font-weight: bolder;
    }
    .badges {
      display: inline-block;
      padding: -0.65em -0.35em;
      font-size: .75em;
      font-weight: 700;
      line-height: 1;
      color: #3b6661;
      text-align: left;
      white-space: nowrap;
      vertical-align: baseline;
      border-radius: 0.25rem;
    }
  </style>
</html>